//
//  LBPrefix.h
//  Pods
//
//  Created by LINAICAI on 2017/9/26.
//

#ifndef LBPrefix_h
#define LBPrefix_h

//图片URL处理
#define LBIMAGEURL(x) [NSURL URLWithString:[LBStringNotNil(x) encodeURL]]

#pragma mark- 列表刷新宏
//刷新列表数据的宏(成功)
#define successToRefresh(tableView) [tableView endFresh];\
[LBLoadingView dismiss];\
[tableView reloadData];\
//刷新列表数据的宏(成功但没有更多数据了)
#define successToRefreshAndNoMoreData(tableView) [tableView endFreshWithNoMoreData];\
[LBLoadingView dismiss];\
[tableView reloadData];\
//刷新列表数据的宏(失败)
#define failToRefresh(tableView,message) [tableView endFresh];\
[LBLoadingView dismiss];\
[LBAlert say:message];\
//加载列表更多数据的宏(成功)
#define successToLoadMore(tableView) [tableView endLoadMore];\
[LBLoadingView dismiss];\
[tableView reloadData];\
//加载列表更多数据的宏(成功但没有更多数据了)
#define successToLoadMoreAndNoMoreData(tableView) [tableView endLoadMoreWithNoMoreData];\
[LBLoadingView dismiss];\
[tableView reloadData];\
//加载列表更多数据的宏(失败)
#define failToLoadMore(tableView,message) [tableView endLoadMore];\
[LBLoadingView dismiss];\
[LBAlert say:message];\

#pragma mark- 全局常量
//APP ID
#define APP_ID @"1102047294"
//客服固话
#define APP_PHONE @"400-1836-882"
//客服移动电话
#define APP_MOBILE @"18620090105"
//公司网站
#define LB_URL @"https://www.lianj.com/"
//公司网站静态资源前缀
#define LB_URL_PUBLIC(n) [@"https://www.lianj.com/public/" stringByAppendingString:n]

#pragma mark- 全局固定链接
#define APP_URL_LINK [NSString stringWithFormat:@"https://%@",[[[NSBundle mainBundle] infoDictionary] objectForKey:@"APP_URL_LINK"]]

#define UMENG_APP_KEY ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"UMENG_APP_KEY"])

#define WX_APP_ID ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"WX_APP_ID"])
#define WX_APP_SECRET ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"WX_APP_SECRET"])
#define WX_APP_URL ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"WX_APP_URL"])

#define QQ_APP_ID ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"QQ_APP_ID"])
#define QQ_APP_KEY ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"QQ_APP_KEY"])
#define QQ_APP_URL ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"QQ_APP_URL"])

#define WB_APP_KEY ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"WB_APP_KEY"])
#define WB_APP_SECRET ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"WB_APP_SECRET"])
#define WB_APP_URL ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"WB_APP_URL"])

#define XG_APP_ACCESSID ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"XG_APP_ACCESSID"])
#define XG_APP_SECRETKEY ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"XG_APP_SECRETKEY"])

#pragma mark- 快速Open一个路由的宏
#define LBHomeOpen(n) NSString *url = [kHomeApplicationScheme stringByAppendingString:n];\
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:url]];\

#define LBUserOpen(n) NSString *url = [kUserApplicationScheme stringByAppendingString:n];\
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:url]];\

#define LBPayOpen(n) NSString *url = [kPayApplicationScheme stringByAppendingString:n];\
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:url]];\

#define LBTenderOpen(n) NSString *url = [kTenderApplicationScheme stringByAppendingString:n];\
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:url]];\

#define LBResourceOpen(n) NSString *url = [kResourceApplicationScheme stringByAppendingString:n];\
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:url]];\

#define LBOrderOpen(n) NSString *url = [kOrderApplicationScheme stringByAppendingString:n];\
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:url]];\

#define LBRecruitOpen(n) NSString *url = [kRecruitApplicationScheme stringByAppendingString:n];\
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:url]];\

#define LBCategoryOpen(n) NSString *url = [kCategoryApplicationScheme stringByAppendingString:n];\
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:url]];\

#define LBBeeOpen(n) NSString *url = [kBeeApplicationScheme stringByAppendingString:n];\
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:url]];\

#define LBShareOpen(n) NSString *url = [kShareApplicationScheme stringByAppendingString:n];\
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];\

#define LBUnionOpen(n) NSString *url = [kUnionNumberApplicationScheme stringByAppendingString:n];\
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];\

#define LBDiscussOpen(n) NSString *url = [kDiscussesApplicationScheme stringByAppendingString:n];\
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];\

#pragma mark- 通过bundle取图片
#define LBHomeImage(n)  [UIImage imageNamed:[@"HomeCenter.bundle/" stringByAppendingString:n]]
#define LBUserImage(n)  [UIImage imageNamed:[@"UserCenter.bundle/" stringByAppendingString:n]]
#define LBPayImage(n)  [UIImage imageNamed:[@"PayCenter.bundle/" stringByAppendingString:n]]
#define LBTenderImage(n)  [UIImage imageNamed:[@"TenderCenter.bundle/" stringByAppendingString:n]]
#define LBResourceImage(n)  [UIImage imageNamed:[@"ResourceCenter.bundle/" stringByAppendingString:n]]
#define LBOrderImage(n)  [UIImage imageNamed:[@"OrderCenter.bundle/" stringByAppendingString:n]]
#define LBRecruitImage(n)  [UIImage imageNamed:[@"RecruitCenter.bundle/" stringByAppendingString:n]]
#define LBCategoryImage(n)  [UIImage imageNamed:[@"CategoryCenter.bundle/" stringByAppendingString:n]]
#define LBBeeImage(n)  [UIImage imageNamed:[@"BeeCenter.bundle/" stringByAppendingString:n]]
#define LBShareImage(n)  [UIImage imageNamed:[@"ShareCenter.bundle/" stringByAppendingString:n]]
#define LBUnionImage(n)  [UIImage imageNamed:[@"UnionNumberCenter.bundle/" stringByAppendingString:n]]
#define LBDiscussImage(n)  [UIImage imageNamed:[@"DiscussesCenter.bundle/" stringByAppendingString:n]]

#pragma mark- Debug模式下打印日志和当前行数|Release模式下关闭打印
#ifndef __OPTIMIZE__
#define NSLog(FORMAT, ...) fprintf(stderr,"\n打印方法-------------->%s\n打印内容-------------->:%s\n", __FUNCTION__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#else
#define NSLog(...) {}
#endif

#pragma mark- 异步GCD宏
#define BACK(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)
#define MAIN(block) dispatch_async(dispatch_get_main_queue(),block)

#pragma mark - 系统版本判断
#define IOS7            ([[[UIDevice currentDevice] systemVersion] integerValue] >= 7)
#define IOS8            ([[[UIDevice currentDevice] systemVersion] integerValue] >= 8)
#define IOS9            ([[[UIDevice currentDevice] systemVersion] integerValue] >= 9)
#define IOS10            ([[[UIDevice currentDevice] systemVersion] integerValue] >= 10)
#define IOS11            ([[[UIDevice currentDevice] systemVersion] integerValue] >= 11)

#pragma mark - 屏幕尺寸
#define SCREEN_W [[UIScreen mainScreen] bounds].size.width
#define SCREEN_H [[UIScreen mainScreen] bounds].size.height
#define SCREEN_MAX_LENGTH (MAX(SCREEN_W, SCREEN_H))

#pragma mark - 手机设备类型判断
#define IS_IPHONE   (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_IPAD     (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_RETINA   ([[UIScreen mainScreen] scale] >= 2.0)

#define IS_IPHONE_4      ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)

#define IS_IPHONE_5      ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)

#define IS_IPHONE_4and5  (IS_IPHONE_4 || IS_IPHONE_5)

#define IS_IPHONE_6       ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) : NO)

///IPHONE_6P有放大模式
#define IS_IPHONE_6P     ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? (CGSizeEqualToSize(CGSizeMake(1125, 2001), [[UIScreen mainScreen] currentMode].size) || CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size)) : NO)

#define IS_IPHONE_X      ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)


#pragma mark - 颜色
#define LBCOLOR(r,g,b)  [UIColor colorWithR:(r) G:(g) B:(b)A:1]
#define LBCOLORA(r,g,b,a)  [UIColor colorWithR:(r) G:(g) B:(b)A:(a)]

#pragma mark - 字体
#define LBFONT(a)       [UIFont systemFontOfSize:(a)]

#pragma mark - 布局边距
#define LBCustomViewContentLeftMargin     g_fitFloat(@[@13,@15,@15]) //标准左边边距
#define LBCustomViewContentRightMargin    g_fitFloat(@[@13,@15,@15]) //标准右边边距
#define LBCustomViewContentViewToViewMargin    g_fitFloat(@[@5,@8,@8]) //标准view间隙



#define weakSelf(object) @weakify(object)
#define stongify(object) @strongify(object)

#define WS(weakSelf)  __weak __typeof(&*self)weakSelf = self;

//字符串是否为空
#define IsStrEmpty(_ref)    (((_ref) == nil) || ([(_ref) isEqual:[NSNull null]]) ||([(_ref)isEqualToString:@""]))
//数组是否为空
#define IsArrEmpty(_ref)    (((_ref) == nil) || ([(_ref) isEqual:[NSNull null]]) ||([(_ref) count] == 0))

#define avoidStringNil(_ref)  _ref = IsStrEmpty(_ref) ? @"" : _ref

//全局页数请求
#define LBRequestPageSize 10
#define LBRequestFirstPage 1
#endif /* LBPrefix_h */
